package com.api.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.api.entity.Project;
import com.api.service.ProjectService;

@Controller
@RequestMapping("/index")
public class IndexController extends BaseController{
	
	@Autowired
	private ProjectService projectService;
	
	@RequestMapping("/")
	public String index(){
		return "project/projectList";
	}
	@RequestMapping("/home")
	public String home(){
		return "home";
	}
	@RequestMapping("/indexHome")
	public String indexHome(Model model,String project_id){
		model.addAttribute("project_id", project_id);
		model.addAttribute("project", "");
		if(StringUtils.isNotEmpty(project_id)){
			Project  project = projectService.getProjectById(project_id);
			if(project!=null){
				model.addAttribute("project", project);
				String projectName = project.getProjectName();
				if(StringUtils.isNotEmpty(projectName)){
					String tempProjectName = "";
					if(projectName.length()>10){
						tempProjectName = projectName.substring(0, 10)+"..";
					}else{
						tempProjectName = projectName;
					}
					model.addAttribute("hideProjectName", tempProjectName);
				}
			}
		}
		
		
//		SysConfig sysConfig = SysConfig.dao.findFirst("select * from sys_config where name=? limit 1","is_pay");
//		if(sysConfig!=null){
//			setAttr("isPay", sysConfig.getVal());
//		}
		return "index";
	}
	//方便des接口测试的
	//解密之后   再把得到的数据加密返还回去
//	@SuppressWarnings("rawtypes")
//	public void returnDes(){
//		String returnData = "hello world";
//		if(isNullParams("data")){
//			String data_temp = getPara("data");
//			String data = DesUtil.decode(data_temp);
//			Map map = (Map) GsonUtil.fromJsonToObject(data, new TypeToken<Map<String, String>>() {}.getType());
//			returnData = DesUtil.encode(GsonUtil.toJson(map));
//		}
//		renderJson(returnData);
//	}
}
